﻿//======================================================================
//
//        Copyright : Zhengzhou Strawberry Computer Technology Co.,LTD.
//        All rights reserved
//
//        Application:NFinal MVC framework
//        Filename :CsTypeTable.cs
//        Description :读取配置文件中csharp对应的数据库类型,数据库参数枚举类型
//
//        created by Lucas at  2015-6-30`
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Text;

namespace NFinal.DB.Coding
{
    /// <summary>
    /// 读取配置文件中csharp对应的数据库类型,数据库参数枚举类型
    /// </summary>
    public class CsTypeTable
    {
        string fileString = null;
        public CsTypeTable(DBType dbType)
        {
            switch (dbType)
            {
                case DBType.MySql: fileString=NFinal.SqlTemplate.SqlTemplate.mysql_cs; break;
                case DBType.Sqlite: fileString = NFinal.SqlTemplate.SqlTemplate.sqlite_cs; break;
                case DBType.SqlServer: fileString = NFinal.SqlTemplate.SqlTemplate.sqlserver_cs; break;
                case DBType.Oracle: fileString = NFinal.SqlTemplate.SqlTemplate.oracle_cs; break;
                default: fileString = NFinal.SqlTemplate.SqlTemplate.sqlserver_cs; break;
            }
        }
        public Dictionary<string, CsTypeLink> GetCsTypeTableDic()
        {
            Dictionary<string, CsTypeLink> csTypeTableDic = new Dictionary<string, CsTypeLink>();
            System.IO.StringReader sr = new System.IO.StringReader(fileString);
            string[] lines = null;
            string[] sqlDbGetPar = null;
            CsTypeLink table = null;
            string line = null;
            line = sr.ReadLine();
            lines = line.Split('\t');
            while (!string.IsNullOrEmpty(line))
            {
                lines = line.Split('\t');
                table = new CsTypeLink();
                table.csharpType = lines[0];
                sqlDbGetPar = lines[1].Split(':');
                table.sqlDbGetMethod = sqlDbGetPar[0];
                if (sqlDbGetPar.Length > 1)
                {
                    table.sqlDbGetType = sqlDbGetPar[1];
                }
                else
                {
                    table.sqlDbGetType = "";
                }
                table.sqlType = lines[2];
                table.sqlDbType = lines[3];
                csTypeTableDic.Add(table.csharpType, table);
                line = sr.ReadLine();
            }
            sr.Close();
            return csTypeTableDic;
        }
    }
}